package net.wanho.hospital.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.hospital.po.Checks;
import net.wanho.hospital.service.ChecksService;
import net.wanho.hospital.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-12-27
 */
@Api(tags = "接口")
@RestController
@RequestMapping("/checks")
@RequiredArgsConstructor
public class ChecksController {

    private final ChecksService checksService;

    @ApiOperation("分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public AjaxResult findPage(@ApiParam("当前页") @PathVariable int pageNum,@ApiParam("页大小") @PathVariable int pageSize, Checks checks){
        IPage page = checksService.findPage(pageNum,pageSize,checks);
        return AjaxResult.success(page);
    }

    @ApiOperation("按主键查询")
    @GetMapping("/{chId}")
    public AjaxResult getById(@ApiParam("学号") @PathVariable Serializable chId){
        return AjaxResult.success(checksService.getById(chId));
    }

    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@RequestBody Checks stu){
        checksService.save(stu);
        return AjaxResult.success();
    }

    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody Checks checks){
        checksService.updateById(checks);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除")
    @DeleteMapping("/{chId}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable chId){
        checksService.removeById(chId);
        return AjaxResult.success();
    }
}
